package com.example.animations.activities;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.annotation.Nullable;

import com.example.animations.R;
import com.example.animations.controls.TestView;

public class RTAnimationActivity extends Activity {
    private TestView _testView;
    private Button _animateButton;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rt_animation);

        _testView = findViewById(R.id.test_view);

        _animateButton = findViewById(R.id.animate_button);
        _animateButton.setOnClickListener(this::onAnimateClick);
        findViewById(R.id.freeze_button).setOnClickListener(this::onFreezeClick);
    }

    private void onAnimateClick(View view) {
        long millis = 3000;

        _animateButton.setEnabled(false);
        _animateButton.postDelayed(() -> _animateButton.setEnabled(true), millis);
        _testView.startAnim(millis);
    }

    private void onFreezeClick(View view) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ignored) {
        }
    }
}
